package com.springboot.study.tests.nio;

import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

/**
 * @Author: guodong
 * @Date: 2021/5/12 10:12
 * @Version: 1.0
 * @Description:
 */
public class Test {
    public static void main(String[] args){
        try {
            FileChannel readChannel = FileChannel.open(Paths.get("D:/bbb.txt"), StandardOpenOption.READ);
            FileChannel writeChannel = FileChannel.open(Paths.get("D:/qqq.txt"), StandardOpenOption.WRITE, StandardOpenOption.CREATE);
            MappedByteBuffer data = readChannel.map(FileChannel.MapMode.READ_ONLY, 0, 1024 * 1024 * 40);
            //数据传输
            writeChannel.write(data);
            readChannel.close();
            writeChannel.close();
        }catch (Exception e){
            System.out.println(e.getStackTrace());
        }
    }

}
